package com.zhz.lib.cms.utils.zhz;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.zhz.lib.cms.domain.type.Sortmap;
import com.zhz.project.common.util.hibernate.BaseDAO;
import com.zhz.project.common.util.zhzutil.ZhzStringUtil;

public class ZhzSortMapUtil {

    /**
     * 根据fatherId得到所有的子类型列表
     * @return
     */
    @SuppressWarnings("unchecked")
    public static List<String[]> getChildSortMapList(Integer fatherId, BaseDAO baseDao) {
        ArrayList<String[]> arraylist = new ArrayList<String[]>();

        List<Sortmap> list = baseDao.findbyorderlimit("Sortmap", "fatherId",
            Integer.toString(fatherId), "order by sortMapId ASC");

        if (list != null && list.size() > 0) {
            String[] departnameInfo = null;
            // 遍历表中的元素，存于 ArrayList中
            int i = 0;
            for (Iterator<Sortmap> it = list.iterator(); it.hasNext();) {
                Sortmap smp = it.next();
                departnameInfo = new String[2];
                departnameInfo[0] = smp.getSortMapId().toString();
                departnameInfo[1] = smp.getValue();
                arraylist.add(departnameInfo);
                i++;
            }
        }
        return arraylist;
    }

    /**
     * 获取特定的类型记录
     *
     * @param request
     * @param baseDao
     * @param TABLE
     * @param KEY
     * @param name
     */
    public static Sortmap getSortmap(String sortMapId, BaseDAO baseDao) {
        Sortmap sortmap = null;
        if (ZhzStringUtil.isNotNull(sortMapId)) {
            sortmap = (Sortmap) baseDao.findOneObject("Sortmap", "sortMapId", sortMapId);
        }
        return sortmap;
    }
}
